package hu.cskassai.sad.model.factory.hibernate;

import hu.cskassai.sad.business.vo.EdgeVO;
import hu.cskassai.sad.business.vo.VertexVO;
import hu.cskassai.sad.model.Vertex;
import hu.cskassai.sad.model.factory.DomainFactory;
import hu.cskassai.sad.model.graph.Edge;
import hu.cskassai.sad.model.graph.Vertex2D;
import hu.cskassai.sad.model.graph.internal.EdgeImpl;
import hu.cskassai.sad.model.graph.internal.Vertex2DImpl;

import java.awt.Point;
import java.awt.geom.Point2D;
import java.math.BigDecimal;
import java.util.UUID;

public class DomainFactoryImpl implements DomainFactory {
	
	public Edge createEdge(final Vertex2D fromVertex, final Vertex2D toVertex) {
		final Edge edge = new EdgeImpl();
		edge.setFromVertex(fromVertex);
		edge.setToVertex(toVertex);
		return edge;
	}
	
	public Vertex2D createVertex2d(final int x, final int y) {
		final Vertex2D vertex2d = new Vertex2DImpl(new Point(x, y));
		vertex2d.setId(UUID.randomUUID());
		return vertex2d;
	}
	
	public Edge createEdge(final EdgeVO edgeVO, final Vertex2D fromVertex, final Vertex2D toVertex) {
		final Edge edge = new EdgeImpl();
		edge.setId(UUID.fromString(edgeVO.getId()));
		edge.setWeight(new BigDecimal(edgeVO.getWeight()));
		edge.setToVertex(toVertex);
		edge.setFromVertex(fromVertex);
		return edge;
	}
	
	public Vertex2D createVertex2d(final VertexVO vertexVO) {
		final Vertex2D vertex2d = new Vertex2DImpl(vertexVO.getPoint());
		vertex2d.setId(UUID.fromString(vertexVO.getId()));
		return vertex2d;
	}
	
	public Vertex2D createVertex2d(final Point2D location) {
		final Vertex2D vertex2d = new Vertex2DImpl(new Point((int) location.getX(), (int) location.getY()));
		vertex2d.setId(UUID.randomUUID());
		return vertex2d;
	}
	
}
